package com.zhang.controller.communication;

import cn.dev33.satoken.annotation.SaCheckPermission;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.zhang.common.util.result.R;
import com.zhang.common.util.result.RUtils;
import com.zhang.communication.entity.Bulletin;
import com.zhang.communication.dto.AnnounceSearchDTO;
import com.zhang.communication.service.IBulletinService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * <p>
 * 系统通告表 前端控制器
 * </p>
 *
 * @author 创世神
 * @since 2024-06-06
 */
@RestController
@RequestMapping("/communication/bulletin")
public class BulletinController {
    @Autowired
    private IBulletinService bulletinService;
    @PostMapping
    @SaCheckPermission("system-bulletin")
    public R createBulletin(@RequestBody Bulletin bulletin){
        bulletinService.createBulletin(bulletin);
        return RUtils.successMsg("新增成功");
    }
    @GetMapping("list")
    @SaCheckPermission("system-bulletin")
    public R getBulletinList(AnnounceSearchDTO announceSearchDTO){
        Page<Bulletin> bulletinPage=bulletinService.getBulletinList(announceSearchDTO);
        return RUtils.successData(bulletinPage);
    }

    /**获取未阅读的通告信息
     * @return {@link R}
     */
    @GetMapping("using/list")
    public R getUsingBulletin(){
       List<Bulletin> bulletins= bulletinService.getUsingBulletin();
        return RUtils.successData(bulletins);
    }

}
